
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>开始 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.2">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="dynamic-matching.html" />
    
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../installation.html">
            
                <a href="../installation.html">
            
                    
                    安装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" >
            
                <span>
            
                    
                    基础
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.3.1" data-path="getting-started.html">
            
                <a href="getting-started.html">
            
                    
                    开始
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="dynamic-matching.html">
            
                <a href="dynamic-matching.html">
            
                    
                    动态路由匹配
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="nested-routes.html">
            
                <a href="nested-routes.html">
            
                    
                    嵌套路由
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="navigation.html">
            
                <a href="navigation.html">
            
                    
                    编程式导航
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="named-routes.html">
            
                <a href="named-routes.html">
            
                    
                    命名路由
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="named-views.html">
            
                <a href="named-views.html">
            
                    
                    命名视图
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.7" data-path="redirect-and-alias.html">
            
                <a href="redirect-and-alias.html">
            
                    
                    重定向 和 别名
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.8" data-path="history-mode.html">
            
                <a href="history-mode.html">
            
                    
                    HTML5 History 模式
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" >
            
                <span>
            
                    
                    进阶
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../advanced/navigation-guards.html">
            
                <a href="../advanced/navigation-guards.html">
            
                    
                    导航钩子
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../advanced/meta.html">
            
                <a href="../advanced/meta.html">
            
                    
                    路由元信息
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../advanced/transitions.html">
            
                <a href="../advanced/transitions.html">
            
                    
                    过渡动效
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../advanced/data-fetching.html">
            
                <a href="../advanced/data-fetching.html">
            
                    
                    数据获取
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../advanced/scroll-behavior.html">
            
                <a href="../advanced/scroll-behavior.html">
            
                    
                    滚动行为
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../advanced/lazy-loading.html">
            
                <a href="../advanced/lazy-loading.html">
            
                    
                    懒加载
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" >
            
                <span>
            
                    
                    API 文档
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../api/router-link.html">
            
                <a href="../api/router-link.html">
            
                    
                    router-link
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../api/router-view.html">
            
                <a href="../api/router-view.html">
            
                    
                    router-view
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../api/route-object.html">
            
                <a href="../api/route-object.html">
            
                    
                    路由信息对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../api/options.html">
            
                <a href="../api/options.html">
            
                    
                    Router 构造配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="../api/router-instance.html">
            
                <a href="../api/router-instance.html">
            
                    
                    Router 实例
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="../api/component-injections.html">
            
                <a href="../api/component-injections.html">
            
                    
                    对组件注入
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >开始</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="getting-started">Getting Started</h1>
<blockquote>
<p>&#x6559;&#x7A0B;&#x4E2D;&#x7684;&#x6848;&#x4F8B;&#x4EE3;&#x7801;&#x5C06;&#x4F7F;&#x7528; <a href="https://github.com/lukehoban/es6features" target="_blank">ES2015</a> &#x6765;&#x7F16;&#x5199;&#x3002;</p>
</blockquote>
<p>&#x7528; Vue.js + vue-router &#x521B;&#x5EFA;&#x5355;&#x9875;&#x5E94;&#x7528;&#xFF0C;&#x662F;&#x975E;&#x5E38;&#x7B80;&#x5355;&#x7684;&#x3002;&#x4F7F;&#x7528; Vue.js &#x65F6;&#xFF0C;&#x6211;&#x4EEC;&#x5C31;&#x5DF2;&#x7ECF;&#x628A;&#x7EC4;&#x4EF6;&#x7EC4;&#x5408;&#x6210;&#x4E00;&#x4E2A;&#x5E94;&#x7528;&#x4E86;&#xFF0C;&#x5F53;&#x4F60;&#x8981;&#x628A; vue-router &#x52A0;&#x8FDB;&#x6765;&#xFF0C;&#x53EA;&#x9700;&#x8981;&#x914D;&#x7F6E;&#x7EC4;&#x4EF6;&#x548C;&#x8DEF;&#x7531;&#x6620;&#x5C04;&#xFF0C;&#x7136;&#x540E;&#x544A;&#x8BC9; vue-router &#x5728;&#x54EA;&#x91CC;&#x6E32;&#x67D3;&#x5B83;&#x4EEC;&#x3002;&#x4E0B;&#x9762;&#x662F;&#x4E2A;&#x57FA;&#x672C;&#x4F8B;&#x5B50;&#xFF1A;</p>
<h3 id="html">HTML</h3>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;https://unpkg.com/vue/dist/vue.js&quot;</span>&gt;</span><span class="undefined"></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;https://unpkg.com/vue-router/dist/vue-router.js&quot;</span>&gt;</span><span class="undefined"></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;app&quot;</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Hello App!<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-comment">&lt;!-- &#x4F7F;&#x7528; router-link &#x7EC4;&#x4EF6;&#x6765;&#x5BFC;&#x822A;. --&gt;</span>
    <span class="hljs-comment">&lt;!-- &#x901A;&#x8FC7;&#x4F20;&#x5165; `to` &#x5C5E;&#x6027;&#x6307;&#x5B9A;&#x94FE;&#x63A5;. --&gt;</span>
    <span class="hljs-comment">&lt;!-- &lt;router-link&gt; &#x9ED8;&#x8BA4;&#x4F1A;&#x88AB;&#x6E32;&#x67D3;&#x6210;&#x4E00;&#x4E2A; `&lt;a&gt;` &#x6807;&#x7B7E; --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">router-link</span> <span class="hljs-attr">to</span>=<span class="hljs-string">&quot;/foo&quot;</span>&gt;</span>Go to Foo<span class="hljs-tag">&lt;/<span class="hljs-name">router-link</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">router-link</span> <span class="hljs-attr">to</span>=<span class="hljs-string">&quot;/bar&quot;</span>&gt;</span>Go to Bar<span class="hljs-tag">&lt;/<span class="hljs-name">router-link</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
  <span class="hljs-comment">&lt;!-- &#x8DEF;&#x7531;&#x51FA;&#x53E3; --&gt;</span>
  <span class="hljs-comment">&lt;!-- &#x8DEF;&#x7531;&#x5339;&#x914D;&#x5230;&#x7684;&#x7EC4;&#x4EF6;&#x5C06;&#x6E32;&#x67D3;&#x5728;&#x8FD9;&#x91CC; --&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">router-view</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">router-view</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<h3 id="javascript">JavaScript</h3>
<pre><code class="lang-js"><span class="hljs-comment">// 0. &#x5982;&#x679C;&#x4F7F;&#x7528;&#x6A21;&#x5757;&#x5316;&#x673A;&#x5236;&#x7F16;&#x7A0B;&#xFF0C;&#x5C0E;&#x5165;Vue&#x548C;VueRouter&#xFF0C;&#x8981;&#x8C03;&#x7528; Vue.use(VueRouter)</span>

<span class="hljs-comment">// 1. &#x5B9A;&#x4E49;&#xFF08;&#x8DEF;&#x7531;&#xFF09;&#x7EC4;&#x4EF6;&#x3002;</span>
<span class="hljs-comment">// &#x53EF;&#x4EE5;&#x4ECE;&#x5176;&#x4ED6;&#x6587;&#x4EF6; import &#x8FDB;&#x6765;</span>
<span class="hljs-keyword">const</span> Foo = { template: <span class="hljs-string">&apos;&lt;div&gt;foo&lt;/div&gt;&apos;</span> }
<span class="hljs-keyword">const</span> Bar = { template: <span class="hljs-string">&apos;&lt;div&gt;bar&lt;/div&gt;&apos;</span> }

<span class="hljs-comment">// 2. &#x5B9A;&#x4E49;&#x8DEF;&#x7531;</span>
<span class="hljs-comment">// &#x6BCF;&#x4E2A;&#x8DEF;&#x7531;&#x5E94;&#x8BE5;&#x6620;&#x5C04;&#x4E00;&#x4E2A;&#x7EC4;&#x4EF6;&#x3002; &#x5176;&#x4E2D;&quot;component&quot; &#x53EF;&#x4EE5;&#x662F;</span>
<span class="hljs-comment">// &#x901A;&#x8FC7; Vue.extend() &#x521B;&#x5EFA;&#x7684;&#x7EC4;&#x4EF6;&#x6784;&#x9020;&#x5668;&#xFF0C;</span>
<span class="hljs-comment">// &#x6216;&#x8005;&#xFF0C;&#x53EA;&#x662F;&#x4E00;&#x4E2A;&#x7EC4;&#x4EF6;&#x914D;&#x7F6E;&#x5BF9;&#x8C61;&#x3002;</span>
<span class="hljs-comment">// &#x6211;&#x4EEC;&#x665A;&#x70B9;&#x518D;&#x8BA8;&#x8BBA;&#x5D4C;&#x5957;&#x8DEF;&#x7531;&#x3002;</span>
<span class="hljs-keyword">const</span> routes = [
  { path: <span class="hljs-string">&apos;/foo&apos;</span>, component: Foo },
  { path: <span class="hljs-string">&apos;/bar&apos;</span>, component: Bar }
]

<span class="hljs-comment">// 3. &#x521B;&#x5EFA; router &#x5B9E;&#x4F8B;&#xFF0C;&#x7136;&#x540E;&#x4F20; `routes` &#x914D;&#x7F6E;</span>
<span class="hljs-comment">// &#x4F60;&#x8FD8;&#x53EF;&#x4EE5;&#x4F20;&#x522B;&#x7684;&#x914D;&#x7F6E;&#x53C2;&#x6570;, &#x4E0D;&#x8FC7;&#x5148;&#x8FD9;&#x4E48;&#x7B80;&#x5355;&#x7740;&#x5427;&#x3002;</span>
<span class="hljs-keyword">const</span> router = <span class="hljs-keyword">new</span> VueRouter({
  routes <span class="hljs-comment">// &#xFF08;&#x7F29;&#x5199;&#xFF09;&#x76F8;&#x5F53;&#x4E8E; routes: routes</span>
})

<span class="hljs-comment">// 4. &#x521B;&#x5EFA;&#x548C;&#x6302;&#x8F7D;&#x6839;&#x5B9E;&#x4F8B;&#x3002;</span>
<span class="hljs-comment">// &#x8BB0;&#x5F97;&#x8981;&#x901A;&#x8FC7; router &#x914D;&#x7F6E;&#x53C2;&#x6570;&#x6CE8;&#x5165;&#x8DEF;&#x7531;&#xFF0C;</span>
<span class="hljs-comment">// &#x4ECE;&#x800C;&#x8BA9;&#x6574;&#x4E2A;&#x5E94;&#x7528;&#x90FD;&#x6709;&#x8DEF;&#x7531;&#x529F;&#x80FD;</span>
<span class="hljs-keyword">const</span> app = <span class="hljs-keyword">new</span> Vue({
  router
}).$mount(<span class="hljs-string">&apos;#app&apos;</span>)

<span class="hljs-comment">// &#x73B0;&#x5728;&#xFF0C;&#x5E94;&#x7528;&#x5DF2;&#x7ECF;&#x542F;&#x52A8;&#x4E86;&#xFF01;</span>
</code></pre>
<p>&#x4F60;&#x53EF;&#x4EE5;&#x770B;&#x770B;&#x8FD9;&#x4E2A;&#x4F8B;&#x5B50;
<a href="http://jsfiddle.net/yyx990803/xgrjzsup/" target="_blank">live</a>&#x3002;</p>
<p>&#x8981;&#x6CE8;&#x610F;&#xFF0C;&#x5F53; <code>&lt;router-link&gt;</code> &#x5BF9;&#x5E94;&#x7684;&#x8DEF;&#x7531;&#x5339;&#x914D;&#x6210;&#x529F;&#xFF0C;&#x5C06;&#x81EA;&#x52A8;&#x8BBE;&#x7F6E; class &#x5C5E;&#x6027;&#x503C;  <code>.router-link-active</code>&#x3002;&#x67E5;&#x770B; <a href="../api/router-link.html">API &#x6587;&#x6863;</a> &#x5B66;&#x4E60;&#x66F4;&#x591A;&#x76F8;&#x5173;&#x5185;&#x5BB9;&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                
                <a href="dynamic-matching.html" class="navigation navigation-next navigation-unique" aria-label="Next page: 动态路由匹配">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"开始","level":"1.3.1","depth":2,"next":{"title":"动态路由匹配","level":"1.3.2","depth":2,"path":"essentials/dynamic-matching.md","ref":"essentials/dynamic-matching.md","articles":[]},"previous":{"title":"基础","level":"1.3","depth":1,"ref":"","articles":[{"title":"开始","level":"1.3.1","depth":2,"path":"essentials/getting-started.md","ref":"essentials/getting-started.md","articles":[]},{"title":"动态路由匹配","level":"1.3.2","depth":2,"path":"essentials/dynamic-matching.md","ref":"essentials/dynamic-matching.md","articles":[]},{"title":"嵌套路由","level":"1.3.3","depth":2,"path":"essentials/nested-routes.md","ref":"essentials/nested-routes.md","articles":[]},{"title":"编程式导航","level":"1.3.4","depth":2,"path":"essentials/navigation.md","ref":"essentials/navigation.md","articles":[]},{"title":"命名路由","level":"1.3.5","depth":2,"path":"essentials/named-routes.md","ref":"essentials/named-routes.md","articles":[]},{"title":"命名视图","level":"1.3.6","depth":2,"path":"essentials/named-views.md","ref":"essentials/named-views.md","articles":[]},{"title":"重定向 和 别名","level":"1.3.7","depth":2,"path":"essentials/redirect-and-alias.md","ref":"essentials/redirect-and-alias.md","articles":[]},{"title":"HTML5 History 模式","level":"1.3.8","depth":2,"path":"essentials/history-mode.md","ref":"essentials/history-mode.md","articles":[]}]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"essentials/getting-started.md","mtime":"2017-03-04T12:16:27.892Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-03-06T16:00:44.406Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

